﻿using System;
using System.Collections.Generic;
using Gameplay.PVE.Utils;
using UnityEngine;
using XLua;
using Yoozoo.Framework.Core;

namespace Gameplay.PVE.Survivor
{
    public class BulletConfig
    {
        public int id;
        public int move_type;
        public int shape_type;
        public List<float> shape_params;
        public List<int> elements;

        public int destroy_type;
        public float destroy_param;
        
        public float speed;
        public int model_id;
        public int effect_model_id;
        public int create_effect_id;
        public int destroy_effect_id;
        public int hit_effect_id;
        public int critical_effect_id;
        public int in_hand_frame;

        public int jump_times;
        public int jump_effect;
        public float miss_rate;
        public float max_distance;
        public Dictionary<string, float> param;
        public Dictionary<string, int> param_int;
        public float collision_cd;

        public float element_interval;
        
        public float locktarget_show_collision;
        public int locktarget_advframe;

        public List<int> destroy_bullets;
        
        public float GetShapeParam(int index)
        {
            if (shape_params.Count > index)
            {
                return shape_params[index];
            }
            return 0;
        }

        public float GetParam(string key)
        {
            if(param.TryGetValue(key,out var value))
            {
                return value;
            }
            return 0;
        }
        
        public int GetParamInt(string key)
        {
            if(param_int.TryGetValue(key,out var value))
            {
                return value;
            }
            return 0;
        }
    }
    
    public partial class BattleConfigManager
    {
        private Dictionary<int, BulletConfig> bulletMap;
        public BulletConfig GetBulletConfig(int id)
        {
            if (bulletMap.TryGetValue(id,out var config))
            {
                return config;
            }
            UnityEngine.Debug.LogError("子弹配置找不到" + id);
            return null;
        }
        public static void PreloadBulletConfig(LuaTable table)
        {
            PveUtils.PreloadRpgConfig(table,ref Instance.bulletMap);
        }
    }
}
